package net.myspring.common.utils;

import net.myspring.common.mybatis.dialect.Dialect;
import net.myspring.common.mybatis.dialect.MySQLDialect;
import net.myspring.common.mybatis.dialect.OracleDialect;
import net.myspring.common.mybatis.provider.ProviderContext;
import net.myspring.middle.domain.Account;

/**
 * Created by liuj on 2016-08-18.
 */
public class ThreadLocalContext {

    private Account account;
    private String companyName;
    private String dataSourceType;
    private ProviderContext providerContext;

    private String dhSessionId;

    private static ThreadLocal<ThreadLocalContext> threadLocal = new ThreadLocal<ThreadLocalContext>();

    public static ThreadLocalContext get() {
        if (threadLocal.get() == null) {
            ThreadLocalContext threadLocalContext = new ThreadLocalContext();
            threadLocal.set(threadLocalContext);
        }
        return threadLocal.get();
    }

    public void remove() {
        this.account = null;
        this.companyName = null;
        this.dataSourceType = "";
        this.providerContext = null;
        this.dhSessionId="";
        threadLocal.remove();
    }

    public Account getAccount() {
        return account;
    }

    public void setAccount(Account account) {
        this.account = account;
    }

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public String getDataSourceType() {
        return dataSourceType;
    }

    public void setDataSourceType(String dataSourceType) {
        this.dataSourceType = dataSourceType;
    }

    public ProviderContext getProviderContext() {
        return providerContext;
    }

    public void setProviderContext(ProviderContext providerContext) {
        this.providerContext = providerContext;
    }

    public String getDhSessionId() {
        return dhSessionId;
    }

    public void setDhSessionId(String dhSessionId) {
        this.dhSessionId = dhSessionId;
    }


    public Dialect getDialect() {
        return new MySQLDialect();
    }
}